import 'dart:convert' as convert;
import 'dart:convert';
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_html/shims/dart_ui_real.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:marquee/marquee.dart';
import 'package:sp_util/sp_util.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:yp/Xwidgets/cache_image.dart';
import 'package:yp/config/config.dart';
import 'package:yp/config/event_bus.dart';
import 'package:yp/config/upgrade_util.dart';
import 'package:yp/helper.dart';
import 'package:yp/http/upload_app_http.dart';
import 'package:yp/router.dart';
import 'package:yp/services/api.dart';

import '../../../../helper.dart';
import 'logic.dart';
import 'recommended/hot_selling_goods/view.dart';
import 'state.dart';

class MallPage extends StatefulWidget {
  MallPage({Key key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _MallPage();
  }
}

class _MallPage extends State<MallPage> with AutomaticKeepAliveClientMixin {
  final MallLogic logic = Get.put(MallLogic());
  final MallState state = Get.find<MallLogic>().state;

  @override
  void initState() {
    super.initState();
    if (!kIsWeb) {
      _getVersion();
    }
  }

  /// 第三方店铺头部样式
  Widget thirdShopTopWidget() {
    var shopInfos = SpUtil.getObject(Config.GET_SHOP_INFO);
    return Container(
      padding: const EdgeInsets.only(bottom: 3),
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage("assets/images/home_navigation.png"),
          fit: BoxFit.cover,
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            height: ScreenUtil().statusBarHeight + 10,
          ),

          Container(
            padding: const EdgeInsets.symmetric(horizontal: 10),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                InkWell(
                  onTap: () {
                    logic.getAndGoThirdShop(goMain: true);
                  },
                  child: Icon(Icons.arrow_back_ios_new,
                      color: const Color(0xffffffff)),
                ),
                Expanded(
                  child: Padding(
                    padding: EdgeInsets.only(
                      top: setWidth(10),
                      bottom: setWidth(10),
                    ),
                    child: Container(
                      padding: EdgeInsets.only(
                          right: setWidth(10), left: setWidth(10)),
                      child: InkWell(
                        onTap: () => Get.toNamed(RouteConfig.commoditySearch),
                        child: Container(
                          height: 27,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(14),
                          ),
                          padding: EdgeInsets.symmetric(horizontal: 9),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              SizedBox(width: 5),
                              Icon(
                                Icons.search_rounded,
                                size: 14,
                                color: Color(0xffcccccc),
                              ),
                              SizedBox(width: 5),
                              Text(
                                '圣诞转球',
                                style: TextStyle(
                                  color: Color(0xffcccccc),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
                // IconButton(
                //   onPressed: () {},
                //   icon: Icon(Icons.more_horiz, color: Colors.white),
                // ),
              ],
            ),
          ),
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
            child: InkWell(
              onTap: () {
                // logic.goToThirdShop();
              },
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                      margin: const EdgeInsets.only(right: 10),
                      width: setWidth(80),
                      height: setWidth(80),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        color: const Color(0xfff4f4f4),
                        borderRadius: BorderRadius.circular(4),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black12,
                            blurRadius: 2,
                          ),
                        ],
                      ),
                      child: Image.network(shopInfos['ec_shop_logo'] == null ||
                              shopInfos['ec_shop_logo'] == ''
                          ? Config.orderEmpty
                          : shopInfos['ec_shop_logo'])
                      // child: Text(
                      //   '暂无\n图片',
                      //   style: TextStyle(
                      //       color: const Color(0xff999999), fontSize: 12),
                      // ),
                      ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Expanded(
                              child: Text(
                                shopInfos['shop_name'] ?? '',
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: const Color(0xffffffff),
                                  fontWeight: FontWeight.bold,
                                  fontSize: 14,
                                ),
                              ),
                            ),
                          ],
                        ),
                        SizedBox(height: 3),
                        InkWell(
                          onTap: () {
                            state.isFavoriteShop
                                ? logic
                                    .getFavoriteShopRemove(shopInfos['shop_id'])
                                : logic
                                    .getFavoriteShopAdd(shopInfos['shop_id']);
                          },
                          child: Container(
                            decoration: BoxDecoration(
                              border: Border.all(
                                color: const Color(0xffCCCCCC),
                              ),
                              borderRadius: BorderRadius.circular(20),
                            ),
                            padding: const EdgeInsets.only(top: 2, bottom: 2),
                            width: 90,
                            child: state.isFavoriteShop
                                ? Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Icon(
                                        Icons.favorite,
                                        color: const Color(0xffffffff),
                                        size: 12,
                                      ),
                                      Padding(
                                        padding: EdgeInsets.only(left: 3),
                                        child: Text(
                                          '已收藏',
                                          style: TextStyle(
                                            color: const Color(0xffffffff),
                                            fontSize: 12,
                                          ),
                                        ),
                                      )
                                    ],
                                  )
                                : Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Icon(
                                        Icons.favorite_border_outlined,
                                        color: const Color(0xffffffff),
                                        size: 12,
                                      ),
                                      Padding(
                                        padding: EdgeInsets.only(left: 3),
                                        child: Text(
                                          '收藏',
                                          style: TextStyle(
                                            color: const Color(0xffffffff),
                                            fontSize: 12,
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MallLogic>(builder: (logic) {
      return Scaffold(
        body: Stack(
          children: [
            Container(
              color: Colors.transparent,
              child: Column(
                children: [
                  logic.state.isChangeShop == 1
                      ? thirdShopTopWidget()
                      : Container(
                          decoration: BoxDecoration(
                            image: DecorationImage(
                              image: AssetImage(
                                  "assets/images/home_navigation.png"),
                              fit: BoxFit.cover,
                            ),
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              SizedBox(
                                height: ScreenUtil().statusBarHeight + 10,
                              ),
                              Center(
                                child: Image.asset(
                                  'assets/images/logoMain.png',
                                  height: 22,
                                  fit: BoxFit.fitHeight,
                                ),
                              ),
                              Padding(
                                padding: EdgeInsets.only(
                                  top: setWidth(34),
                                  bottom: setWidth(32),
                                ),
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Container(
                                      width: setWidth(180),
                                      child: Row(
                                        children: [
                                          Padding(
                                            padding: EdgeInsets.only(
                                              left: 11,
                                              right: 5,
                                            ),
                                            child: Image.asset(
                                              'assets/images/locationIcon.png',
                                              width: 10,
                                              height: 14,
                                            ),
                                          ),
                                          Expanded(
                                            child: InkWell(
                                              onTap: () {
                                                Get.toNamed(RouteConfig
                                                    .selectShippingAddress);
                                              },
                                              child: Text(
                                                logic
                                                    .getCurrentLocationDescription(),
                                                maxLines: 1,
                                                overflow: TextOverflow.ellipsis,
                                                style: TextStyle(
                                                  color: Colors.white,
                                                  fontSize: 14,
                                                ),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Padding(
                                      // padding: EdgeInsets.only(right: setWidth(30)),
                                      padding:
                                          EdgeInsets.only(right: setWidth(10)),
                                      child: InkWell(
                                        onTap: () => Get.toNamed(
                                            RouteConfig.commoditySearch),
                                        child: Container(
                                          // width: setWidth(370), // 370 + 160
                                          width: setWidth(440),
                                          height: 27,
                                          decoration: BoxDecoration(
                                            color: Colors.white,
                                            borderRadius:
                                                BorderRadius.circular(14),
                                          ),
                                          padding: EdgeInsets.symmetric(
                                            horizontal: 9,
                                          ),
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.start,
                                            children: [
                                              Icon(
                                                Icons.search_rounded,
                                                size: 12,
                                                color: Color(0xffcccccc),
                                              ),
                                              SizedBox(
                                                width: 5,
                                              ),
                                              Text(
                                                state.keyword,
                                                style: TextStyle(
                                                  color: Color(0xffcccccc),
                                                  fontSize: 12,
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),
                                    ),
                                    Container(
                                      // width: setWidth(160),
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceAround,
                                        children: [

                                          InkWell(
                                            onTap: () {
                                              // print('9999 营业厅图标点击事件 9999');
                                              Get.toNamed(
                                                  RouteConfig
                                                      .nearbyBusinessHall,
                                                  arguments:
                                                      logic.locationResult);
                                            },
                                            child: Container(
                                              padding: EdgeInsets.symmetric(
                                                  horizontal: setWidth(20),
                                                  vertical: setWidth(3)),
                                              child: Image.asset(
                                                'assets/images/businessHall-icon.png',
                                                width: setWidth(46),
                                                height: setWidth(46),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                  Expanded(
                    child: Container(
                      color: Color(0xffEFF0F3),
                      child: state == null ||
                              state.templateList == null ||
                              state.templateList.length == 0
                          ? Row()
                          : ListView(
                              padding: EdgeInsets.all(0),
                              children: state.templateList.map((itemModel) {
                                return _itemWidget(dataMap: itemModel);
                              }).toList(),
                            ),

                    ),
                  )
                ],
              ),
            ),
            if (state.signInBool &&
                (state.signInImage != null && state.signInImage != ''))
              Positioned(
                top: state.dy,
                left: state.dx,
                child: GestureDetector(
                  onTap: () {
                    print('点击事件！！！');
                    Get.toNamed(RouteConfig.signIn).then((value) {
                      logic.signInClick();
                    });
                  },
                  behavior: HitTestBehavior.opaque,
                  child: Draggable(
                    affinity: Axis.horizontal,
                    // child: Image.asset(
                    //   'assets/images/poster.png',
                    //   width: 50.0,
                    //   height: 50.0,
                    // ),
                    // feedback: Image.asset(
                    //   'assets/images/poster.png',
                    //   width: 50.0,
                    //   height: 50.0,
                    // ),
                    child: Image.network(
                      state.signInImage,
                      width: 50,
                      height: 50,
                    ),
                    feedback: Image.network(
                      state.signInImage,
                      width: 50,
                      height: 50,
                    ),
                    childWhenDragging: Container(),
                    onDragCompleted: () {
                      print(
                          'Draggable --> onDragCompleted 拖动到DragTarget控件上时回调。');
                    },
                    onDragEnd: (DraggableDetails details) {
                      print(
                          'Draggable --> onDragEnd 拖动结束时回调。 --> ${details.offset}');
                      if (details.offset.dx < 0) {
                        state.dx = 0;
                      } else if (details.offset.dx > setWidth(750) - 50.0) {
                        state.dx = setWidth(750) - 50.0;
                      } else {
                        state.dx = details.offset.dx;
                      }

                      if (details.offset.dy < ScreenUtil().statusBarHeight) {
                        // statusBarHeight  ScreenUtil
                        state.dy = ScreenUtil().statusBarHeight;
                      } else if (details.offset.dy >
                          setHeight(1334) -
                              50 -
                              (56.0 + MediaQuery.of(context).padding.bottom)) {
                        // 56 + MediaQuery.of(context).padding.bottom
                        state.dy = setHeight(1334) -
                            50 -
                            (56.0 + MediaQuery.of(context).padding.bottom);
                      } else {
                        state.dy = details.offset.dy;
                      }
                      logic.update();
                    },
                    onDraggableCanceled: (Velocity velocity, Offset offset) {
                      print(
                          'Draggable --> onDraggableCanceled 未拖动到DragTarget控件上时回调。--> $offset');
                    },
                    onDragStarted: () {
                      print('Draggable --> onDragStarted  开始拖动时回调');
                    },
                  ),
                ),
              ),
          ],
        ),
      );
    });
  }

  // item
  Widget _itemWidget({
    Map<String, dynamic> dataMap,
  }) {
    if (dataMap['widgets_sign'] == 1) {
      //组件类型 1 轮播图，2 快捷导航，3 拼图，4 商品展示，9 图片热区，11跑马灯
      // return SliverToBoxAdapter(
      //   child: _bannerWidget(dataMap: dataMap),
      // );
      return _bannerWidget(dataMap: dataMap);
    } else if (dataMap['widgets_sign'] == 4) {
      var map = convert.jsonDecode(dataMap['widgets_data_params']);
      List list = [];
      if (state == null ||
          state.goodsList == null ||
          state.angleInformationList == null) return Row();
      state.goodsList.forEach((e) {
        if (e['widgets_data_id'] == dataMap['widgets_data_id']) {
          list = e['listMap'];
        }
      });
      List list1 = [];
      print(">>>>>>>>>>>INFO =$list1");

      state.angleInformationList.forEach((e) {
        if (e['widgets_data_id'] == dataMap['widgets_data_id']) {
          list1 = e['listMap'];
        }
      });
      return HotSellingGoodsPage(
        map: dataMap,
        goodsList: list,
        angleInformationList: list1,
      );
    } else if (dataMap['widgets_sign'] == 2) {
      // return SliverToBoxAdapter(
      //   child: _entranceWidget(dataMap: dataMap),
      // );
      return _entranceWidget(dataMap: dataMap);
    } else if (dataMap['widgets_sign'] == 3) {
      // return SliverToBoxAdapter(
      //   child: _hottestCommodityWidget(dataMap: dataMap),
      // );
      return _hottestCommodityWidget(dataMap: dataMap);
    } else if (dataMap['widgets_sign'] == 9) {
      // return SliverToBoxAdapter(
      //   child: _imageHotZone(dataMap: dataMap),
      // );
      return _imageHotZone(dataMap: dataMap);
    } else if (dataMap['widgets_sign'] == 11) {
      var map = convert.jsonDecode(dataMap['widgets_data_params']);
      String imageUrl = map['iconImage'][0];
      String titleStr = map['textHorseRace'];
      String colorStr = map['textColor'];
      return Column(
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: '${dataMap['widgets_data_title']}',
                                style: TextStyle(
                                  color: Color(0xff222222),
                                  fontSize: 15,
                                ),
                              ),
                              WidgetSpan(
                                child: SizedBox(width: 6),
                              ),
                              TextSpan(
                                text: dataMap['widgets_data_sub_title'],
                                style: TextStyle(
                                  color: Colors.red.withOpacity(
                                      0.7), //black.withOpacity(0.3),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffbbbbbb),
                ),
              ],
            ),
          ),
          Container(
            height: setWidth(100),
            padding: EdgeInsets.symmetric(
                horizontal: setWidth(20), vertical: setWidth(23)),
            child: Row(
              children: [
                Container(
                  width: setWidth(60),
                  height: setWidth(60),
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(setWidth(10)),
                    child: Image.network(
                      imageUrl,
                      width: setWidth(60),
                      height: setWidth(60),
                      fit: BoxFit.cover,
                    ),
                  ),
                ),
                SizedBox(width: setWidth(20)),
                Expanded(
                  child: Marquee(
                    text: titleStr,
                    style: TextStyle(
                      color: getColorFromHex(colorStr),
                      height: 1.5,
                    ),
                    scrollAxis: Axis.horizontal,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    blankSpace: 20.0,
                    // 间距
                    pauseAfterRound: Duration(seconds: 1),
                    accelerationDuration: Duration(seconds: 1),
                    accelerationCurve: Curves.linear,
                    decelerationDuration: Duration(milliseconds: 500),
                    decelerationCurve: Curves.easeOut,
                  ),
                ),
              ],
            ),
          ),
        ],
      );
    } else if (dataMap['widgets_sign'] == 8) {
      if (state == null || state.couponsList == null) return Row();
      // print('=================优惠券===============  dataMap = $dataMap');
      var map = convert.jsonDecode(dataMap['widgets_data_params']);
      // print('+++++++++++++++++++++++++++++++ map = $map');

      List list = [];
      state.couponsList.forEach((element) {
        if (element['widgets_data_id'] == dataMap['widgets_data_id']) {
          list = element['listMap'];
        }
      });

      var params = jsonDecode(dataMap['widgets_data_params']);
      print("tmpl.=${params}");
      return Container(
        color: Colors.white,
        margin: EdgeInsets.only(top: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            if (dataMap['widgets_title'] != null &&
                dataMap['widgets_title'] != '')
              Padding(
                padding: const EdgeInsets.only(left: 15, top: 15),
                child: Text(
                  "${dataMap['widgets_title']}",
                  style: TextStyle(fontSize: 18),
                ),
              ),
            _discountCouponWidget(
              couponList: list,
              col: map["select_coupon"],
              params: params,
            ),
          ],
        ),
      );
    }

    return Container(
      height: 0,
      color: Colors.white,
    );
  }

  // 图片热区
  Widget _imageHotZone({
    Map<String, dynamic> dataMap,
  }) {
    var imageHotZoneMap = convert.jsonDecode(dataMap['widgets_data_params']);
    // hotList
    List hotList = imageHotZoneMap['hotList'];
    List<Widget> stackArray = [
      cacheImage(
        imageUrl: '${imageHotZoneMap['pic_url']}',
        width: MediaQuery.of(context).size.width,
        fit: BoxFit.fitWidth,
      ),
    ];
    hotList.map((e) {
      stackArray.add(
        Positioned(
          left: setWidth(double.parse(e['left'].toString())),
          top: setWidth(double.parse(e['top'].toString())),
          right: setWidth(double.parse(e['radio'].toString())),
          child: InkWell(
            onTap: () {
              Map<String, dynamic> map = {
                'linktype': e['targetType'].toString(),
                'linktarget': e['targetPage'].toString(),
                'shop_id': e['shop_id'].toString(),
              };
              if (e['targetType'].toString() == '26') {
                logic.getCouponOrToCouponGoodsList(couponModel: map);
              } else {
                jump(
                  url: e['targetType'].toString(),
                  model: map,
                );
              }
            },
            child: Container(
              width: setWidth(double.parse(e['width'].toString())),
              height: setWidth(double.parse(e['height'].toString())),
            ),
          ),
        ),
      );
    }).toList();

    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(
        top: setWidth(20),
      ),
      child: Column(
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: dataMap['widgets_data_title'] ?? "",
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 15,
                                ),
                              ),
                              WidgetSpan(
                                child: SizedBox(width: 4),
                              ),
                              TextSpan(
                                text: dataMap['widgets_data_sub_title'] ?? "",
                                style: TextStyle(
                                  color: Colors.black.withOpacity(0.3),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Offstage(
                      offstage: dataMap['widgets_data_show_more'] == 0,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                              // print(' 更多按钮点击事件 商品 横排  ');
                            },
                            child: Container(
                              height: setWidth(60),
                              width: setWidth(80),
                              alignment: Alignment.centerRight,
                              child: Text(
                                '更多',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 12,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffefefef),
                ),
              ],
            ),
          ),
          Stack(
            children: stackArray,
          ),
        ],
      ),
    );
  }

  // 轮播图
  Widget _bannerWidget({
    Map<String, dynamic> dataMap,
  }) {
    var bannerMap = convert.jsonDecode(dataMap['widgets_data_params']);
    double ratio, height;
    if (bannerMap['ratio'] == null || bannerMap['ratio'] == '') {
      if (bannerMap['height'] == null || bannerMap['height'] == '') {
        height = 220;
      } else {
        height = double.parse(bannerMap['height'].toString());
      }
    } else {
      ratio = double.parse(bannerMap['ratio'].toString());
      height = (MediaQuery.of(context).size.width - 20) / ratio;
    }
    height = height + 20;
    List bannerList = bannerMap['pictures'];

    DateTime currentTime = DateTime.now();
    DateTime beginTime;
    DateTime endTime;
    List listBannerMap = [];

    Map locationMap = SpUtil.getObject(Config.USER_CURRENT_LOCATION);
    //print("locationMaplocationMaplocationMap=${locationMap['AMapResult']}");
    var res = "";
    if (locationMap != null &&
        locationMap['AMapResult'] != null &&
        locationMap['AMapResult']['adCode'] != null) {
      // print("locationMap['AMapResult']['adCode']${locationMap['AMapResult']['adCode']}");
      var a = locationMap['AMapResult']['adCode'].split("");
      if (a.length > 5) {
        a[2] = "0";
        a[3] = "0";
        a[4] = "0";
        a[5] = "0";
      }

      res = a.join();
    }

    print("res");

    if (bannerList != null && bannerList.length > 0) {
      for (int i = 0; i < bannerList.length; i++) {
        var map = bannerList[i];
        String begin_time = map['begin_time'] ?? '';
        String end_time = map['end_time'] ?? '';

        List<dynamic> region = [];
        if (map['region'] is List) {
          region = map['region'];
        }

        print("region====$region");
        if (begin_time != '' && end_time != '') {
          beginTime = DateTime.parse('${map['begin_time']}');
          endTime = DateTime.parse('${map['end_time']}');
          if (currentTime.isAfter(beginTime) && currentTime.isBefore(endTime)) {
            if (region.length > 0) {
              if (region.toString().contains(res.toString())) {
                listBannerMap.add(map);
              }
            } else {
              listBannerMap.add(map);
            }
          }
        } else if (begin_time != '' && end_time == '') {
          beginTime = DateTime.parse('${map['begin_time']}');
          if (currentTime.isAfter(beginTime)) {
            if (region.length > 0) {
              if (region.toString().contains(res.toString())) {
                listBannerMap.add(map);
              }
            } else {
              listBannerMap.add(map);
            }
          }
        } else if (begin_time == '' && end_time != '') {
          endTime = DateTime.parse('${map['end_time']}');
          if (currentTime.isBefore(endTime)) {
            if (region.length > 0) {
              if (region.toString().contains(res.toString())) {
                listBannerMap.add(map);
              }
            } else {
              listBannerMap.add(map);
            }
          }
        } else {
          if (region.length > 0) {
            if (region.toString().contains(res.toString())) {
              listBannerMap.add(map);
            }
          } else {
            listBannerMap.add(map);
          }
        }
      }
    }

    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [
            Color(0xffEA5B05),
            Color(0xffEFF0F3),
          ],
        ),
      ),
      padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
      child: Column(
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] ==
                0, // widgets_data_show_title   0 不展示  1 展示
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    Container(
                      width: 2,
                      height: 20,
                      color: Colors.red,
                    ),
                    SizedBox(
                      width: 4,
                    ),
                    Text(
                      dataMap['widgets_data_title'],
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 18,
                      ),
                    ),
                    SizedBox(
                      width: 4,
                    ),
                    Text(
                      dataMap['widgets_data_sub_title'],
                      style: TextStyle(
                        color: Colors.black.withOpacity(0.3),
                        fontSize: 13,
                      ),
                    ),
                  ],
                ),
                Offstage(
                  offstage: dataMap['widgets_data_show_more'] ==
                      0, // widgets_data_show_more 0 不显示 1 显示
                  child: InkWell(
                    onTap: () {
                      // print(' 更多点击事件 ！！！！ ');
                    },
                    child: Text(
                      '更多',
                      style: TextStyle(
                        color: Color(0xffaaaaaa),
                        fontSize: 13,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          if (listBannerMap.length > 0)
            Container(
              height: setWidth(height * 2),
              padding: EdgeInsets.only(
                top: setWidth(20),
                bottom: setWidth(20),
              ),
              child: Swiper(
                key: ValueKey('${listBannerMap.length.toString()}'),
                // autoplay: true,
                onTap: (int index) {
                  Map map = listBannerMap[index];
                  jump(
                    url: map['linktype'].toString(),
                    model: map,
                  );
                },
                itemCount: listBannerMap.length,
                itemBuilder: (BuildContext context, int index) {
                  return Container(
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(setWidth(10)),
                      child: CachedImage(
                        width: MediaQuery.of(context).size.width - 20,
                        height: setWidth((height - 20) * 2),
                        margin: EdgeInsets.zero,
                        scale: BoxFit.fill,
                        path: listBannerMap[index]['pic_url'],
                      ),
                    ),
                  );
                },
                pagination: SwiperPagination(),
              ),
            ),
        ],
      ),
    );
  }

  // 九宫格
  Widget _entranceWidget({
    Map<String, dynamic> dataMap,
  }) {
    int countInt = 0; // 每行显示数量   item数量 小于等于8 每行4 个    大于8 每行5个
    var bannerMap = convert.jsonDecode(dataMap['widgets_data_params']);
    Color titleColor = Color(0xff222222);
    if (bannerMap['color'] != null && bannerMap['color'] != '') {
      titleColor = getColorFromHex('${bannerMap['color']}');
    }
    List entranceList = bannerMap['navs'];
    print("=============bannerMap============");
    print(bannerMap);
    print(entranceList);
    print("=============bannerMap============");

    // entranceList.removeWhere((element) {
    //   //删除包含燃气缴费的功能入口
    //   String name = element['icon_name'];
    //   return name.contains('粮油调味') || name.contains('休闲食品');
    // });

    countInt = entranceList.length > 4 ? 5 : 4;
    int upperNum;
    if(entranceList.length >20){
      upperNum = (entranceList.length/10).ceil();
    }else if(entranceList.length > 10 && entranceList.length <= 20){
      upperNum = 2;
    }else if(entranceList.length == 10){
      upperNum = 1;
    }else if(entranceList.length > 5 && entranceList.length < 10){
      upperNum = 2;
    }else{
      upperNum = 1;
    }
    _itemWidget({
      Map<String, dynamic> map,
    }) {
      return InkWell(
        onTap: () {
          jump(
            url: map['linktype'].toString(),
            model: map,
          );
        },
        child: Container(
          width: countInt == 5 ? setWidth(142) : setWidth(177.5),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              map['pic_url'] != ''
                  ? CachedImage(
                      path: map['pic_url'],
                      width: setWidth(90),
                      height: setWidth(90),
                      scale: BoxFit.fill,
                    )
                  : ClipOval(
                      child: Container(
                        color: Color(0xffaaaaaa),
                        width: setWidth(90),
                        height: setWidth(90),
                      ),
                    ),
              SizedBox(
                height: setWidth(10),
              ),
              Text(
                map['icon_name'],
                style: TextStyle(
                  color: titleColor,
                  fontSize: 13,
                ),
              ),
              SizedBox(
                height: setWidth(10),
              ),
            ],
          ),
        ),
      );
    }

    return Container(
      color: Color(0xffEFF0F3),
      padding: EdgeInsets.symmetric(horizontal: setWidth(18)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: dataMap['widgets_data_title'],
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 15,
                                ),
                              ),
                              WidgetSpan(
                                child: SizedBox(width: 4),
                              ),
                              TextSpan(
                                text: dataMap['widgets_data_sub_title'],
                                style: TextStyle(
                                  color: Colors.black.withOpacity(0.3),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Offstage(
                      offstage: dataMap['widgets_data_show_more'] == 0,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                              // print(' 更多按钮点击事件 商品 横排  ');
                            },
                            child: Container(
                              height: setWidth(60),
                              width: setWidth(80),
                              alignment: Alignment.centerRight,
                              child: Text(
                                '更多',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 12,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffefefef),
                ),
              ],
            ),
          ),
          SizedBox(height: setWidth(10)),
          Container(
            height: entranceList.length >9 ? setWidth(355) : setWidth(185),
            padding: EdgeInsets.only(
              top: setWidth(20),
              // bottom: setWidth(20),
            ),
            child: Swiper(
                // key: ValueKey('${entranceList.length.toString()}'),
                loop: false,
                onTap: (int index) {

                },
                itemCount: upperNum,
                itemBuilder: (BuildContext context, int index){
                  List itemList = [];
                  if(entranceList.length >=6){
                    if(entranceList.length >9){
                      if(entranceList.length >20){
                        int start = index *10 ;
                        int end = start + 10;
                        if(end >= entranceList.length){
                          end = entranceList.length;
                        }
                        itemList = entranceList.sublist(start,end);
                      }else{
                        if(entranceList.length == 10){
                          itemList = entranceList;
                        }else{
                          if(index == 0){
                            for(int i=0;i<10;i++){
                              itemList.add(entranceList[i]);
                            }
                          }else{
                            for(int i=10;i<entranceList.length;i++){
                              itemList.add(entranceList[i]);
                            }
                          }
                        }
                      }
                    }else{
                      if(index == 0){
                        for(int i=0;i<5;i++){
                          itemList.add(entranceList[i]);
                        }
                      }else{
                        for(int i=5;i<entranceList.length;i++){
                          itemList.add(entranceList[i]);
                        }
                      }
                    }
                  }else{
                    itemList = entranceList;
                  }
                  return Wrap(
                    direction: Axis.horizontal,
                    runSpacing: setWidth(20), // 排间距
                    children: itemList.map((e) {
                      return _itemWidget(map: e);
                    }).toList(),
                  );
                },
                pagination: entranceList.length >5 && entranceList.length != 10?
                SwiperPagination(margin: EdgeInsets.all(0)) :
                null,
            ),
          ),
        ],
      ),
    );
  }

  // 券
  Widget _discountCouponWidget({
    List couponList,
    int col = 1,
    dynamic params,
  }) {
    print("colcolcolcolc=$col");

    if (couponList.length == 0) {
      return SizedBox();
    }

    if (col == 2) {
      return Container(
        width: 750.w,
        padding: EdgeInsets.only(
          left: setWidth(10),
          top: setWidth(22),
          right: setWidth(20),
          // bottom: setWidth(28),
        ),
        color: Colors.white,
        child: Wrap(
          // mainAxisAlignment: MainAxisAlignment.spaceBetween,
          alignment: WrapAlignment.spaceBetween,
          children: couponList
              .asMap()
              .map(
                (index, model) => MapEntry(
                    index,
                    GestureDetector(
                      onTap: () {
                        print('领券点击事件！！！');

                        if (model['relation'] == 0) {
                          if (model['stock_qty'] > 0) {
                            var params = {
                              'use_platform': 2,
                              'coupon_num_id': model['series'].toString(),
                              'usr_num_id': SpUtil.getInt('empeNumId'),
                              'access_token': SpUtil.getString('token'),
                              'qsource': 301,
                              'relation_indate': "永久有效",
                              'user_num_id': SpUtil.getInt('empeNumId'),
                            };
                            Api.getCoupon(params).listen((event) {
                              if (event['code'] == 0) {
                                toast('领券成功');
                                model['relation'] = 1;
                                setState(() {});
                              }
                            });
                          } else {
                            toast('库存不足');
                          }
                        } else {
                          if (model['use_begin_date'] != '' &&
                              model['use_begin_end'] != '' &&
                              model['use_begin_date'] != null &&
                              model['use_begin_end'] != null) {
                            var startDate =
                                DateTime.tryParse(model['use_begin_date']);
                            var endDate =
                                DateTime.tryParse(model['use_begin_end']);
                            var disable =
                                (DateTime.now().isBefore(startDate)) ||
                                    (DateTime.now().isAfter(endDate));
                            if (disable) {
                              toast('未到优惠券使用时间');
                              return false;
                            }
                          }
                          Get.toNamed(RouteConfig.couponGoodsList, arguments: {
                            'coupon_id': model['series'],
                          });
                        }
                      },
                      child: Stack(
                        children: [
                          Container(
                            width: 350.w,
                            margin: EdgeInsets.only(bottom: 20.w),
                            child: Row(
                              children: [
                                Container(
                                  width: setWidth(288),
                                  height: setWidth(160),
                                  decoration: BoxDecoration(
                                    color: hexToColor(params['coupon1']),
                                    borderRadius: BorderRadius.only(
                                      topLeft: Radius.circular(setWidth(10)),
                                      bottomLeft: Radius.circular(setWidth(10)),
                                    ),
                                  ),
                                  padding: EdgeInsets.only(
                                    left: setWidth(28),
                                  ),
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      model['coupontype'] == '0'
                                          ? (Text.rich(
                                              TextSpan(
                                                children: [
                                                  TextSpan(
                                                    text:
                                                        '${double.parse((model['face_value'] / 10).toStringAsFixed(2)).toString().replaceAll('.00', '').replaceAll('.0', '')}',
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 28,
                                                      fontWeight:
                                                          FontWeight.bold,
                                                    ),
                                                  ),
                                                  TextSpan(
                                                    text: '折',
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 16,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ))
                                          : model['coupontype'] == '1'
                                              ? (Text.rich(
                                                  TextSpan(
                                                    children: [
                                                      TextSpan(
                                                        text: '¥',
                                                        style: TextStyle(
                                                          color: hexToColor(
                                                              params[
                                                                  'coupon2']),
                                                          fontSize: 16,
                                                        ),
                                                      ),
                                                      TextSpan(
                                                        text:
                                                            model['face_value']
                                                                .toString()
                                                                .replaceAll(
                                                                    '.0', ''),
                                                        style: TextStyle(
                                                          color: hexToColor(
                                                              params[
                                                                  'coupon2']),
                                                          fontSize: 28,
                                                          fontWeight:
                                                              FontWeight.bold,
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                ))
                                              : (Text.rich(
                                                  TextSpan(
                                                    children: [
                                                      TextSpan(
                                                        text: '免邮',
                                                        style: TextStyle(
                                                          color: hexToColor(
                                                              params[
                                                                  'coupon2']),
                                                          fontSize: 32,
                                                          fontWeight:
                                                              FontWeight.bold,
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                )),
                                      SizedBox(height: 2),
                                      if (model['least_cost'] == 0)
                                        Text(
                                          "无门槛",
                                          style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 12),
                                        ),
                                      if (model['least_cost'] != 0)
                                        RichText(
                                          maxLines: 1,
                                          text: TextSpan(
                                            children: [
                                              TextSpan(
                                                text: '满',
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 12,
                                                ),
                                              ),
                                              TextSpan(
                                                text: model['least_cost']
                                                    .toString()
                                                    .replaceAll('.0', ''),
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 13,
                                                ),
                                              ),
                                              TextSpan(
                                                text: '元使用',
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 12,
                                                ),
                                              )
                                            ],
                                          ),
                                        ),
                                      SizedBox(height: 2),
                                      if (model['fixed_term'] == null)
                                        Container(
                                          width: 300.w,
                                          child: Text(
                                            '有效期：${DateFormat('yyyy.MM.dd').format(DateTime.parse(model['use_begin_date']))} - ${DateFormat('yyyy.MM.dd').format(DateTime.parse(model['use_begin_end']))}',
                                            maxLines: 1,
                                            style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 12,
                                            ),
                                            overflow: TextOverflow.ellipsis,
                                          ),
                                        ),
                                      if (model['fixed_term'] != null)
                                        Text(
                                          '有效期：自领券${model["fixed_term"]}日内',
                                          maxLines: 1,
                                          style: TextStyle(
                                            color:
                                                hexToColor(params['coupon2']),
                                            fontSize: 12,
                                          ),
                                        ),
                                      SizedBox(
                                        height: setWidth(5),
                                      ),
                                    ],
                                  ),
                                ),
                                Container(
                                  width: setWidth(60),
                                  height: setWidth(160),
                                  padding: EdgeInsets.symmetric(
                                      horizontal: setWidth(20)),
                                  decoration: BoxDecoration(
                                    color: hexToColor(params['coupon6']),
                                    borderRadius: BorderRadius.only(
                                      topRight: Radius.circular(setWidth(10)),
                                      bottomRight:
                                          Radius.circular(setWidth(10)),
                                    ),
                                  ),
                                  alignment: Alignment.center,
                                  child: Text(
                                    model['relation'] == 0 ? '立即领取' : '去使用',
                                    style: TextStyle(
                                      color: hexToColor(params['coupon7']),
                                      fontSize: 11,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Positioned(
                            left: setWidth(278),
                            top: -setWidth(10),
                            child: Container(
                              width: setWidth(20),
                              height: setWidth(20),
                              decoration: BoxDecoration(
                                color: Color(0xffEFF0F3),
                                borderRadius:
                                    BorderRadius.circular(setWidth(20)),
                              ),
                            ),
                          ),
                          Positioned(
                            left: setWidth(278),
                            top: setWidth(150),
                            child: Container(
                              width: setWidth(20),
                              height: setWidth(20),
                              decoration: BoxDecoration(
                                color: Color(0xffEFF0F3),
                                borderRadius:
                                    BorderRadius.circular(setWidth(20)),
                              ),
                            ),
                          ),
                        ],
                      ),
                    )),
              )
              .values
              .toList(),
        ),
      );
    }

    return Container(
      padding: EdgeInsets.only(
        left: setWidth(20),
        right: setWidth(20),
        bottom: setWidth(20),
      ),
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: couponList
            .asMap()
            .map((index, model) {
              return MapEntry(
                index,
                Padding(
                  padding: EdgeInsets.only(top: setWidth(20)),
                  child: Container(
                    decoration: BoxDecoration(
                      color: hexToColor(params['coupon1']),
                      borderRadius: BorderRadius.circular(setWidth(14)),
                    ),
                    height: setWidth(160),
                    child: Stack(
                      children: [
                        Row(
                          children: [
                            Container(
                              width: setWidth(236),
                              padding: EdgeInsets.symmetric(
                                  horizontal: setWidth(10)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  model['coupontype'] == '0'
                                      ? (Text.rich(
                                          TextSpan(
                                            children: [
                                              TextSpan(
                                                text:
                                                    '${double.parse((model['face_value'] / 10).toStringAsFixed(2)).toString().replaceAll('.00', '').replaceAll('.0', '')}',
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 28,
                                                  fontWeight: FontWeight.bold,
                                                ),
                                              ),
                                              TextSpan(
                                                text: '折',
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 16,
                                                ),
                                              ),
                                            ],
                                          ),
                                        ))
                                      : model['coupontype'] == '1'
                                          ? (Text.rich(
                                              TextSpan(
                                                children: [
                                                  TextSpan(
                                                    text: '¥',
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 16,
                                                    ),
                                                  ),
                                                  TextSpan(
                                                    text: model['face_value']
                                                        .toString()
                                                        .replaceAll('.0', ''),
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 28,
                                                      fontWeight:
                                                          FontWeight.bold,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ))
                                          : (Text.rich(
                                              TextSpan(
                                                children: [
                                                  TextSpan(
                                                    text: '免邮',
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 32,
                                                      fontWeight:
                                                          FontWeight.bold,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            )),
                                  SizedBox(height: 5),
                                  if (model['least_cost'] == 0)
                                    Text(
                                      "无门槛",
                                      style: TextStyle(
                                          color: hexToColor(params['coupon2']),
                                          fontSize: 12),
                                    ),
                                  if (model['least_cost'] != 0)
                                    RichText(
                                      maxLines: 1,
                                      text: TextSpan(
                                        children: [
                                          TextSpan(
                                            text: '满',
                                            style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 12,
                                            ),
                                          ),
                                          TextSpan(
                                            text: model['least_cost']
                                                .toString()
                                                .replaceAll('.0', ''),
                                            style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 13,
                                            ),
                                          ),
                                          TextSpan(
                                            text: '元使用',
                                            style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 12,
                                            ),
                                          )
                                        ],
                                      ),
                                    ),
                                ],
                              ),
                            ),
                            Container(
                              width: setWidth(474),
                              padding: EdgeInsets.symmetric(
                                  horizontal: setWidth(15)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    // '${model['least_cost']}元代金券',
                                    '${model['title']}',
                                    style: TextStyle(
                                      color: hexToColor(params['coupon5']),
                                      fontSize: 12,
                                    ),
                                  ),
                                  if (model['fixed_term'] == null)
                                    Text(
                                      '有效期：${DateFormat('yyyy.MM.dd').format(DateTime.parse(model['use_begin_date']))} - ${DateFormat('yyyy.MM.dd').format(DateTime.parse(model['use_begin_end']))}',
                                      maxLines: 1,
                                      style: TextStyle(
                                        color: hexToColor(params['coupon5']),
                                        fontSize: 12,
                                      ),
                                    ),
                                  if (model['fixed_term'] != null)
                                    Text(
                                      '有效期：自领券${model["fixed_term"]}日内',
                                      maxLines: 1,
                                      style: TextStyle(
                                        color: hexToColor(params['coupon5']),
                                        fontSize: 12,
                                      ),
                                    ),
                                  SizedBox(height: 5),
                                  GestureDetector(
                                    onTap: () {
                                      print('领券点击事件！！！');

                                      if (model['relation'] == 0) {
                                        if (model['stock_qty'] > 0) {
                                          var params = {
                                            'use_platform': 2,
                                            'coupon_num_id':
                                                model['series'].toString(),
                                            'usr_num_id':
                                                SpUtil.getInt('empeNumId'),
                                            'access_token':
                                                SpUtil.getString('token'),
                                            'qsource': 301,
                                            'relation_indate': "永久有效",
                                            'user_num_id':
                                                SpUtil.getInt('empeNumId'),
                                          };
                                          Api.getCoupon(params).listen((event) {
                                            if (event['code'] == 0) {
                                              toast('领券成功');
                                              model['relation'] = 1;
                                              setState(() {});
                                            }
                                          });
                                        } else {
                                          toast('库存不足');
                                        }
                                      } else {
                                        if (model['use_begin_date'] != '' &&
                                            model['use_begin_end'] != '' &&
                                            model['use_begin_date'] != null &&
                                            model['use_begin_end'] != null) {
                                          var startDate = DateTime.tryParse(
                                              model['use_begin_date']);
                                          var endDate = DateTime.tryParse(
                                              model['use_begin_end']);
                                          var disable = (DateTime.now()
                                                  .isBefore(startDate)) ||
                                              (DateTime.now().isAfter(endDate));
                                          if (disable) {
                                            toast('未到优惠券使用时间');
                                            return false;
                                          }
                                        }
                                        Get.toNamed(RouteConfig.couponGoodsList,
                                            arguments: {
                                              'coupon_id': model['series'],
                                            });
                                      }
                                    },
                                    behavior: HitTestBehavior.opaque,
                                    child: Container(
                                      padding: EdgeInsets.only(
                                        left: setWidth(10),
                                        right: setWidth(10),
                                        bottom: setWidth(2),
                                      ),
                                      decoration: BoxDecoration(
                                        color: hexToColor(params['coupon6']),
                                        borderRadius:
                                            BorderRadius.circular(setWidth(6)),
                                      ),
                                      child: Text(
                                        model['relation'] == 0 ? '立即领取' : '去使用',
                                        style: TextStyle(
                                          color: hexToColor(params['coupon7']),
                                          fontSize: 13,
                                        ),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                        Positioned(
                          left: setWidth(226),
                          top: -setWidth(10),
                          child: Container(
                            width: setWidth(20),
                            height: setWidth(20),
                            decoration: BoxDecoration(
                              color: Color(0xffEFF0F3),
                              borderRadius: BorderRadius.circular(setWidth(20)),
                            ),
                          ),
                        ),
                        Positioned(
                          left: setWidth(226),
                          top: setWidth(150),
                          child: Container(
                            width: setWidth(20),
                            height: setWidth(20),
                            decoration: BoxDecoration(
                              color: Color(0xffEFF0F3),
                              borderRadius: BorderRadius.circular(setWidth(20)),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              );
            })
            .values
            .toList(),
      ),
    );
  }

  // 最热单品
  Widget _hottestCommodityWidget({
    Map<String, dynamic> dataMap,
  }) {
    //widgets_data_params
    var hottestMap = convert.jsonDecode(dataMap['widgets_data_params']);
    int countInt = hottestMap['styletag']; // 显示几张图片
    List imageArray = hottestMap['pictures']; // 图片数组

    return Container(
      color: Colors.white,
      child: Column(
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: dataMap['widgets_data_title'],
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 15,
                                ),
                              ),
                              WidgetSpan(
                                child: SizedBox(width: 4),
                              ),
                              TextSpan(
                                text: dataMap['widgets_data_sub_title'],
                                style: TextStyle(
                                  color: Colors.black.withOpacity(0.3),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Offstage(
                      offstage: dataMap['widgets_data_show_more'] == 0,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                              // print(' 更多按钮点击事件 商品 横排  ');
                            },
                            child: Container(
                              height: setWidth(60),
                              width: setWidth(80),
                              alignment: Alignment.centerRight,
                              child: Text(
                                '更多',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 12,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffefefef),
                ),
              ],
            ),
          ),
          countInt == 4
              ? Container(
                  padding: EdgeInsets.only(
                    top: setWidth(26),
                    bottom: setWidth(26),
                  ),
                  child: Padding(
                    padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                    child: Row(
                      children: [
                        imageArray.length >= 1
                            ? InkWell(
                                onTap: () {
                                  Map map = imageArray[0];
                                  jump(
                                    url: map['linktype'].toString(),
                                    model: map,
                                  );
                                },
                                child: CachedImage(
                                  path: imageArray[0]['pic_url'],
                                  width: setWidth(296),
                                  height: setWidth(410),
                                  scale: BoxFit.fill,
                                ),
                              )
                            : Container(
                                width: setWidth(296),
                                height: setWidth(410),
                              ),
                        SizedBox(
                          width: setWidth(14),
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            imageArray.length >= 2
                                ? InkWell(
                                    onTap: () {
                                      Map map = imageArray[1];
                                      jump(
                                        url: map['linktype'].toString(),
                                        model: map,
                                      );
                                    },
                                    child: CachedImage(
                                      path: imageArray[1]['pic_url'],
                                      width: setWidth(390),
                                      height: setWidth(196),
                                      scale: BoxFit.fill,
                                    ),
                                  )
                                : Container(
                                    width: setWidth(390),
                                    height: setWidth(196),
                                  ),
                            SizedBox(
                              height: setWidth(8),
                            ),
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                imageArray.length >= 3
                                    ? InkWell(
                                        onTap: () {
                                          Map map = imageArray[2];
                                          jump(
                                            url: map['linktype'].toString(),
                                            model: map,
                                          );
                                        },
                                        child: CachedImage(
                                          path: imageArray[2]['pic_url'],
                                          width: setWidth(190),
                                          height: setWidth(200),
                                          scale: BoxFit.fill,
                                        ),
                                      )
                                    : Container(
                                        width: setWidth(190),
                                        height: setWidth(200),
                                      ),
                                SizedBox(
                                  width: setWidth(8),
                                ),
                                imageArray.length >= 4
                                    ? InkWell(
                                        onTap: () {
                                          Map map = imageArray[3];
                                          jump(
                                            url: map['linktype'].toString(),
                                            model: map,
                                          );
                                        },
                                        child: CachedImage(
                                          path: imageArray[3]['pic_url'],
                                          width: setWidth(190),
                                          height: setWidth(200),
                                          scale: BoxFit.fill,
                                        ),
                                      )
                                    : Container(
                                        width: setWidth(190),
                                        height: setWidth(200),
                                      ),
                              ],
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                )
              : countInt == 2
                  ? Container(
                      padding: EdgeInsets.symmetric(
                          horizontal: setWidth(20), vertical: setWidth(26)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          imageArray.length >= 1
                              ? InkWell(
                                  onTap: () {
                                    Map map = imageArray[0];
                                    jump(
                                      url: map['linktype'].toString(),
                                      model: map,
                                    );
                                  },
                                  child: CachedImage(
                                    path: imageArray[0]['pic_url'],
                                    width: setWidth(345),
                                    height: setWidth(345),
                                    scale: BoxFit.fill,
                                  ),
                                )
                              : Container(
                                  width: setWidth(345),
                                  height: setWidth(345),
                                  color: Colors.yellow,
                                ),
                          imageArray.length >= 2
                              ? InkWell(
                                  onTap: () {
                                    Map map = imageArray[1];
                                    jump(
                                      url: map['linktype'].toString(),
                                      model: map,
                                    );
                                  },
                                  child: CachedImage(
                                    path: imageArray[1]['pic_url'],
                                    width: setWidth(345),
                                    height: setWidth(345),
                                    scale: BoxFit.fill,
                                  ),
                                )
                              : Container(
                                  width: setWidth(345),
                                  height: setWidth(345),
                                  color: Colors.red,
                                ),
                        ],
                      ),
                    )
                  : countInt == 3
                      ? Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: setWidth(20), vertical: setWidth(26)),
                          child: Row(
                            children: [
                              imageArray.length >= 1
                                  ? InkWell(
                                      onTap: () {
                                        Map map = imageArray[0];
                                        jump(
                                          url: map['linktype'].toString(),
                                          model: map,
                                        );
                                      },
                                      child: CachedImage(
                                        path: imageArray[0]['pic_url'],
                                        width: setWidth(296),
                                        height: setWidth(410),
                                        scale: BoxFit.fill,
                                      ),
                                    )
                                  : Container(
                                      width: setWidth(296),
                                      height: setWidth(410),
                                    ),
                              SizedBox(
                                width: setWidth(14),
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  imageArray.length >= 2
                                      ? InkWell(
                                          onTap: () {
                                            Map map = imageArray[1];
                                            jump(
                                              url: map['linktype'].toString(),
                                              model: map,
                                            );
                                          },
                                          child: CachedImage(
                                            path: imageArray[1]['pic_url'],
                                            width: setWidth(390),
                                            height: setWidth(196),
                                            scale: BoxFit.fill,
                                          ),
                                        )
                                      : Container(
                                          width: setWidth(390),
                                          height: setWidth(196),
                                        ),
                                  SizedBox(
                                    height: setWidth(8),
                                  ),
                                  imageArray.length >= 3
                                      ? InkWell(
                                          onTap: () {
                                            Map map = imageArray[2];
                                            jump(
                                              url: map['linktype'].toString(),
                                              model: map,
                                            );
                                          },
                                          child: CachedImage(
                                            path: imageArray[2]['pic_url'],
                                            width: setWidth(390),
                                            height: setWidth(196),
                                            scale: BoxFit.fill,
                                          ),
                                        )
                                      : Container(
                                          width: setWidth(390),
                                          height: setWidth(196),
                                        ),
                                ],
                              ),
                            ],
                          ),
                        )
                      : Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: setWidth(20), vertical: setWidth(26)),
                          child: imageArray.length >= 1
                              ? InkWell(
                                  onTap: () {
                                    Map map = imageArray[0];
                                    jump(
                                      url: map['linktype'].toString(),
                                      model: map,
                                    );
                                  },
                                  child: cacheImage(
                                    imageUrl: imageArray[0]['pic_url'],
                                    width: setWidth(710),
                                    fit: BoxFit.fitWidth,
                                  ),
                                )
                              : Container(),
                        ),
        ],
      ),
    );

    // 下面是 跑马灯信息
    /*
                SizedBox(
                  height: setWidth(4),
                ),
                Container(
                  height: setWidth(90),
                  width: setWidth(750),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                      top: BorderSide(
                        color: Color(0xffefefef).withOpacity(0.7),
                        width: setWidth(1),
                      ),
                    ),
                  ),
                  padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Image.asset(
                        'assets/images/announcement_image.png',
                        width: setWidth(40),
                        height: setWidth(40),
                        fit: BoxFit.cover,
                      ),
                      SizedBox(
                        width: setWidth(16),
                      ),
                      Expanded(
                        child: Text(
                          '县委常委被调查：对我好一点，我要出去当县委书记',
                          style: TextStyle(
                            color: Color(0xff666666),
                            fontSize: 14,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                */
  }

  // 热销商品
  Widget _hotSellingGoodsWidget({
    Map<String, dynamic> dataMap,
  }) {
    _itemWidget({
      int index,
    }) {
      return Container(
        width: setWidth(180),
        height: setWidth(328),
        padding: EdgeInsets.only(
          top: setWidth(20),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Image.asset(
              'assets/images/avatar.png',
              width: setWidth(180),
              height: setWidth(180),
              fit: BoxFit.cover,
            ),
            SizedBox(
              height: setWidth(20),
            ),
            Text(
              '智能油烟机',
              style: TextStyle(
                color: Color(0xff222222),
                fontSize: 13,
              ),
            ),
            SizedBox(
              height: setWidth(12),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text.rich(
                  TextSpan(
                    children: [
                      TextSpan(
                          text: '¥179',
                          style: TextStyle(
                            color: Color(0xff333333),
                            fontSize: 14,
                          )),
                      TextSpan(
                          text: '+20',
                          style: TextStyle(
                            color: Color(0xff333333),
                            fontSize: 10,
                          )),
                      WidgetSpan(
                        child: Image.asset(
                          'assets/images/integral_image.png',
                          width: setWidth(24),
                          height: setWidth(26),
                          fit: BoxFit.cover,
                        ),
                      ),
                    ],
                  ),
                ),
                // InkWell(
                //   onTap: () {
                //     // print(' 加入购物车图片点击事件！！！ index = $index');
                //   },
                //   child: Image.asset(
                //     'assets/images/shoppingCart_image.png',
                //     width: setWidth(42),
                //     height: setWidth(42),
                //     fit: BoxFit.cover,
                //   ),
                // ),
              ],
            ),
          ],
        ),
      );
    }

    List list = dataMap['style'];

    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(
        top: setWidth(20),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text(
                          dataMap['widgets_data_title'],
                          style: TextStyle(
                            color: Color(0xff333333),
                            fontSize: 15,
                          ),
                        ),
                        SizedBox(
                          width: 4,
                        ),
                        Text(
                          dataMap['widgets_data_sub_title'],
                          style: TextStyle(
                            color: Colors.black.withOpacity(0.3),
                            fontSize: 12,
                          ),
                        ),
                      ],
                    ),
                    Row(
                      children: [
                        InkWell(
                          onTap: () {
                            // print(' 更多按钮点击事件 商品 横排  ');
                          },
                          child: Container(
                            height: setWidth(60),
                            width: setWidth(80),
                            alignment: Alignment.centerRight,
                            child: Text(
                              '更多',
                              style: TextStyle(
                                color: Color(0xff999999),
                                fontSize: 12,
                              ),
                            ),
                          ),
                        ),
                        SizedBox(
                          width: setWidth(20),
                        ),
                      ],
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffefefef),
                ),
              ],
            ),
          ),
          Container(
            width: setWidth(750),
            height: setWidth(340),
            padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
            child: ListView.separated(
              scrollDirection: Axis.horizontal,
              itemBuilder: (context, index) {
                return _itemWidget(index: index);
              },
              separatorBuilder: (BuildContext context, int index) {
                return SizedBox(
                  width: setWidth(15),
                );
              },
              itemCount: list.length,
            ),
          ),
        ],
      ),
    );
  }

  // 推荐商品
  Widget _recommendCommodityWidget() {
    List<String> titleList = [
      '3人团',
      '秒杀',
    ];

    _itemWidget({
      int index,
    }) {
      return InkWell(
        onTap: () {
          // print(' 商品详情 点击事件！！！！');
          // Get.toNamed(RouteConfig.commodityDetails);
        },
        child: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(setWidth(10)),
          ),
          padding: EdgeInsets.only(
            left: setWidth(16),
            top: setWidth(18),
            right: setWidth(16),
            bottom: setWidth(20),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Image.asset(
                'assets/images/avatar.png',
                width: setWidth(314),
                height: setWidth(332),
                fit: BoxFit.cover,
              ),
              SizedBox(
                height: setWidth(6),
              ),
              Text(
                index % 2 == 0 ? '美的精致电饭煲 爱家的人推荐 全家都在用$index' : '美的智能油烟机$index',
                style: TextStyle(
                  color: Color(0xff222222),
                  fontSize: 13,
                ),
              ),
              SizedBox(
                height: setWidth(12),
              ),
              Offstage(
                offstage: index % 3 == 0,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Wrap(
                      direction: Axis.horizontal,
                      spacing: setWidth(10), //列间距
                      alignment: WrapAlignment.start,
                      children: titleList.map((titleStr) {
                        return Container(
                          padding: EdgeInsets.symmetric(
                            horizontal: setWidth(8),
                            vertical: setWidth(4),
                          ),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(setWidth(30)),
                            border: Border.all(
                              width: 1,
                              color: Color(0xffCBB397),
                            ),
                          ),
                          child: Text(
                            titleStr,
                            style: TextStyle(
                              color: Color(0xffCBB397),
                              fontSize: 10,
                            ),
                          ),
                        );
                      }).toList(),
                    ),
                    SizedBox(
                      height: setWidth(14),
                    ),
                  ],
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text.rich(
                    TextSpan(
                      children: [
                        TextSpan(
                            text: '¥',
                            style: TextStyle(
                              color: Color(0xffea5504),
                              fontSize: 10,
                            )),
                        TextSpan(
                            text: '189.00',
                            style: TextStyle(
                              color: Color(0xffea5504),
                              fontSize: 16,
                            )),
                        WidgetSpan(
                          child: SizedBox(
                            width: setWidth(6),
                          ),
                        ),
                        TextSpan(
                            text: '¥179.00+20',
                            style: TextStyle(
                              color: Color(0xff222222),
                              fontSize: 11,
                            )),
                        WidgetSpan(
                          child: Image.asset(
                            'assets/images/integral_image.png',
                            width: setWidth(24),
                            height: setWidth(26),
                            fit: BoxFit.cover,
                          ),
                        ),
                      ],
                    ),
                  ),

                ],
              ),
            ],
          ),
        ),
      );
    }

    return Container(
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.only(
              top: setWidth(48),
              bottom: setWidth(28),
            ),
            child: Image.asset(
              'assets/images/recommendCommodity_image.png',
              width: setWidth(540),
              height: setWidth(30),
              fit: BoxFit.cover,
            ),
          ),
          StaggeredGridView.countBuilder(
            shrinkWrap: true,
            padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
            crossAxisCount: 4,
            itemCount: 20,
            physics: NeverScrollableScrollPhysics(),
            // itemBuilder: (BuildContext context, int index) => Container(
            //   color: Colors.green,
            //   height: index % 3 == 0 ? 80 : (index % 3 == 1 ? 230 : 400),
            //   child: Center(
            //     child: CircleAvatar(
            //       backgroundColor: Colors.white,
            //       child: Text('$index'),
            //     ),
            //   ),
            // ),
            itemBuilder: (BuildContext context, int index) {
              return _itemWidget(index: index);
            },
            staggeredTileBuilder: (index) => StaggeredTile.fit(2),
            mainAxisSpacing: setWidth(14), // 排间距
            crossAxisSpacing: setWidth(14), // 列间距
          ),
        ],
      ),
    );
  }

  void _getVersion() {
    CGHttpClient.getAppVersion((version) {
      setState(() {
        var versionInfo = SpUtil.getObject(CGHttpClient.VersionInfo);
        if (versionInfo != null) {
          if (checkAppVersionUpdate(version, versionInfo['versionName'])) {
            _showUpdateDialog(context, versionInfo);
          }
        }
      });
    });
  }

  bool checkAppVersionUpdate(String oldVersion, String nowVersion) {
    var nowVersionList = nowVersion.split('.');
    var oldVersionList = oldVersion.split('.');
    for (int i = 0;
        i < nowVersionList.length || i < oldVersionList.length;
        i++) {
      if (int.parse(nowVersionList[i]) > int.parse(oldVersionList[i])) {
        return true;
      } else if (int.parse(nowVersionList[i]) < int.parse(oldVersionList[i])) {
        return false;
      }
    }
    return false;
  }

  void _showUpdateDialog(context, updateInfo) {
    showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return DialogWidget(
            title: '升级提示',
            content: updateInfo['desc'].toString(),
            cancelText: '取消',
            confirmText: '升级',
            cancelFun: () async {
              if ('是' == updateInfo['isForceUpdate']) {
                await SystemChannels.platform
                    .invokeMethod('SystemNavigator.pop');
              } else {
                Navigator.pop(context);
              }
            },
            confirmFun: () {
              if ('是' != updateInfo['isForceUpdate']) {
                Navigator.pop(context);
              }
              launch(updateInfo['url']);
            },
          );
        });
  }

  @override
  bool get wantKeepAlive => true;
}
